package com.xinqi.modules.course.clazz.controller.inner;

import com.xinqi.common.base.response.R;
import com.xinqi.common.rocketmq.dto.CourseClassMessageBody;
import com.xinqi.modules.course.clazz.dto.req.ClassQueryDTO;
import com.xinqi.modules.course.clazz.dto.rsp.ClassResultDTO;
import com.xinqi.modules.course.clazz.service.ClassService;
import com.xinqi.modules.course.clazz.service.ClassSyncService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 班级表控制层
 *
 * @author: system
 * @date: 2023/01/17
 */
@RestController
@RequestMapping("/inner/class")
@RequiredArgsConstructor
public class ClassInnerController {

    private final ClassSyncService classSyncService;

    private final ClassService classService;

    @Operation(summary = "班级MQ消息处理接口")
    @PostMapping("/processingClass")
    public R<Void> processingClass(@RequestBody CourseClassMessageBody body) {
        classSyncService.processingClass(body);
        return R.ok();
    }

    @Operation(summary = "根据班级ID获取班级课程信息")
    @GetMapping("/find/{classId}")
    public R<ClassResultDTO> findClass(@PathVariable("classId") Long classId) {
        return R.data(classService.findByClassId(classId));
    }

    @Operation(summary = "获取所有班级信息")
    @GetMapping("/find/all")
    public R<List<ClassResultDTO>> findAll() {
        return R.data(classService.find(new ClassQueryDTO()));
    }

}
